# -*- coding: utf-8 -*-
"""
Created on Sat Sep 17 09:53:35 2016

@author: zhiqiang
"""
dics = {'CC':0,'CT':1,'CA':2,'CG':3,'TC':4,'TT':5,'TA':6,'TG':7,'AC':8,'AT':9,'AA':10,'AG':11,'GC':12,'GT':13,'GA':14,'GG':15}
path = r"D:\2016试题\B\B题附件"
fileName = "genotype.dat"
f = open(path+'\\'+fileName)
genData = f.readlines()
j = 1
result = {}
weiDian = genData[0]#表头
weiDian = weiDian.replace(' ',',')
length = len(weiDian)

file = open('csvtest.txt', 'w')
file.write(weiDian)
for gen_i in genData:#依次取出每行
    if j==1:#如果是第一行跳过，因为是表头
        j+=1
        continue
    ss = gen_i
    for dic_k in dics:
        ss = ss.replace(dic_k,str(dics[dic_k]))
    gen_split = ss.replace(' ',',')
    file.write(gen_split)
file.flush()
file.close()